package final_wearebatman_view;

import final_wearebatman_model.Generator;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;

public class GeneratorView implements Ipaintable {

    private Generator gen;
    private CircuitView circuitview;
    private int posX;
    private int posY;
    private int angle;
    private String name;

    // konstrukor
    public GeneratorView(Generator g, String name, CircuitView cv, int pX, int pY, int a) {
        this.gen = g;
        this.circuitview = cv;
        this.posX = pX;
        this.posY = pY;
        this.angle = a;
        this.name = name;
    }

    // kirajzolas
    public void paint(Graphics2D g) {
        AffineTransform aT = g.getTransform();
        g.translate(posX, posY);
        //g.rotate(this.angle * Math.PI / 180);
        g.drawString("sequence", -58, 13);
        g.drawString(gen.getData(), -58, 30);
        if (this.gen.getOutputData(0) == 1) {
            g.setColor(Color.red);
        } else {
            g.setColor(Color.white);
        }
        g.fillRect(2, 2, 16, 12);
        g.setColor(Color.black);
        g.drawRect(2, 2, 16, 12);
        g.drawLine(20, 8, 28, 8);
        g.setTransform(aT);
    }

    public int getPosX() {
        return this.posX;
    }

    public int getPosY() {
        return this.posY;
    }

    public int getAngle() {
        return this.angle;
    }

    public Point getInputPinPosition(int id) {
        return new Point(posX, posY);
    }

    public Point getOutputPinPosition(int id) {
        Point p = new Point(28, 8);
        AffineTransform aT = new AffineTransform();
        aT.rotate(this.angle * Math.PI / 180);
        aT.transform(p, p);
        return new Point(posX + p.x, posY + p.y);
    }

    public Rectangle getClickArea() {
        return new Rectangle(posX, posY, 20, 16);
    }

    public void onClick() {
        GeneratorSetWindow gs = new GeneratorSetWindow(circuitview, gen.getData());

        gen.setData(gs.data);
    }
}
